package org.lan.controller;

import org.lan.entity.Group;
import org.lan.service.IUserService;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

import javax.inject.Inject;
import java.util.List;
import java.util.Map;

@Controller
@RequestMapping(value = "/user")
public class UserController {

    private IUserService userService;

    @Inject
    public void setUserService(IUserService userService) {
        this.userService = userService;
    }

    @RequestMapping(value = "/{id}/groups", method = RequestMethod.GET)
    public String groups(@PathVariable("id") Integer id, Map<String, Object> map) {
        List<Group> groups = userService.findUserGroupGroupByUserId(id);
        map.put("groups", groups);
        return "/WEB-INF/view/User-Info";
    }
}
